﻿/// ---------------------------------------------
/// 2012.4.27
/// 汪定新
///
/// ---------------------------------------------

///----------------------------------------------
///2012.4.30 汪定新 添加
///


if (typeof ($) != "undefined") {
    $(document).ready(function () {
        var now = new Date();
        y = now.getFullYear();
        m = now.getMonth() + 1;
        d = now.getDate();
        m = m < 10 ? "0" + m : m;
        d = d < 10 ? "0" + d : d;
        var myDate = y + "-" + m + "-" + d
        $("#ReportDate").val(myDate);
        var empId = getPar1('empId');
        instance[0].EmployeeID = empId;
        instance[0].ReportDate = myDate;
        getCurrentSalary(empId);
        //获取员工编号和姓名
        var empCode = getPar1("empCode");
        var empName = getPar1("empName");
        $("#empCode").val(empCode);
        $("#empName").val(empName);
    });
}

//获取员工当前薪资信息
function getCurrentSalary(empId) {
    var url = "../Extend/AjaxData/jsonlist.aspx?entity=hrEmployeeSalary&condition=EmployeeID='" + empId + "' and AvilableStatus=2";
    $.get(url, function (d, s) {
        var list = eval("(" + d + ")");
        if (list.total == 0) {
            //alert("无薪资信息！");
        }
        else {
            for (var o in list.rows) {
                var BaseSalary = list.rows[o].BaseSalary;
                var TrafficAllowance = list.rows[o].TrafficAllowance;
                var DinnerAllowance = list.rows[o].DinnerAllowance;
                var HouseAllowance = list.rows[o].HouseAllowance;
                var AvilableStatus = list.rows[o].AvilableStatus;
                if (typeof (BaseSalary) != "undefined") {
                    $("#PreBaseSalary").val(BaseSalary);
                    $("#PreTrafficAllowance").val(TrafficAllowance);
                    $("#PreDinnerAllowance").val(DinnerAllowance);
                    $("#PreHouseAllowance").val(HouseAllowance);
                    break;
                }
            }
        }
    })
}

//2012.4.29 汪定新 添加
var fnCheckData = function () {
    if (/^\d+(.\d+)?$/.test($("#BaseSalary").val()) == false) {
        return "基本工资需要输入非负数";
    }
    if (/^\d+(.\d+)?$/.test($("#TrafficAllowance").val()) == false) {
        return "交通补贴需要输入非负数";
    }
    if (/^\d+(.\d+)?$/.test($("#HouseAllowance").val()) == false) {
        return "住房补贴需要输入非负数";
    }
    if (/^\d+(.\d+)?$/.test($("#DinnerAllowance").val()) == false) {
        return "伙食补贴需要输入非负数";
    }
//    var now = new Date();
//    y = now.getFullYear();
//    m = now.getMonth() + 1;
//    d = now.getDate();
//    m = m < 10 ? "0" + m : m;
//    d = d < 10 ? "0" + d : d;
//    var begin = y + "-" + m + "-" + d
//    var end = $("#ValidDate").val();
//    if (end == "") {
//        end = "2100-12-30";
//    }
//    if (begin >= end) {
//        return "生效日期小于当前日期，不允许!";
//    }
}
//